package com.java.restaurant.generic.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class RestuarantDBConnection {
	private RestuarantDBConnection() {

	}
	
	private static Connection conn = null;

	public static Connection getConnection() throws Exception {

		// String dbURL = "jdbc:mysql://db4free.net:3306/t3";

		try {
			if (conn == null) {
				Class.forName("com.mysql.jdbc.Driver");
				conn = DriverManager.getConnection("jdbc:mysql://localhost/hotel",
						"test", "test");
				System.out.println("DB Connected:" + conn);
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw e;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("Error: unable to connect database : "
					+ e.getMessage());
			e.printStackTrace();
			throw e;
		}

		return conn;
	}

}
